﻿#ifndef YUTOPP_OAUTH_DETAIL_V1_SYNC_PART_HPP
#define YUTOPP_OAUTH_DETAIL_V1_SYNC_PART_HPP

#include "../../../url_base64.hpp"

namespace webapp
{
	namespace oauth
	{
		namespace detail
		{
			namespace v1
			{
				template<typename Derived, typename Policy>
				class sync_part
				{
					typedef typename Policy::string_type			string_type;
					typedef std::string								binary_type;
					typedef typename Policy::translator_type		translator;

					typedef typename Policy::request_token			request_token;
					typedef typename Policy::access_token			access_token;
					typedef typename Policy::optional_request_token	optional_request_token;
					typedef typename Policy::optional_access_token	optional_access_token;

				public:
					optional_request_token get_request_token( const string_type& body = string_type() )
					{
						translator::decoder_type d;
						error::value e;

						return static_cast<Derived&>(*this).parse_request_response(
								d(
									url::decode(
										static_cast<Derived&>(*this).send_request_token_request( body, e )
										)
									)
								);
					}

					optional_access_token get_access_token( const binary_type& pin, const request_token& request_token )
					{
						translator::decoder_type d;
						error::value e;

						return static_cast<Derived&>(*this).parse_access_response(
								d(
									url::decode(
										static_cast<Derived&>(*this).send_access_token_request(
											pin,
											request_token.first,
											request_token.second,
											e
											)
										)
									)
								);
					}
				};
			} // - v1
		} // - detail
	} // - oauth
} // - webapp

#endif /*YUTOPP_OAUTH_DETAIL_V1_SYNC_PART_HPP*/
